package jue;

public class NumCreater{
    //获得当前毫秒数
    private static long no=System.currentTimeMillis();

    //获取新的序号
    public long getNextNum(){
        synchronized (NumCreater.class){
            no++;
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return no;
        }

    }


    public static void main(String[] args) {
        new Thread(){
            @Override
            public void run() {
//                synchronized (NumCreater.class){
                    System.out.println(new NumCreater().getNextNum());
//                }

            }
        }.start();

        new Thread(){
            @Override
            public void run() {
//                synchronized (NumCreater.class){
                    System.out.println(new NumCreater().getNextNum());
//                }

            }
        }.start();

    }
}
